package top.lt.lt_ssm.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.lt.lt_ssm.bean.prosto;
import top.lt.lt_ssm.service.ProstoService;
import top.lt.lt_ssm.util.SimpleResult;

@Controller
@RequestMapping("/prosto")
public class ProstoConntroller {
		
	@Resource
	private ProstoService prostoService;
	
	@RequestMapping("/getall")
	@ResponseBody
	public SimpleResult GetAll(){
		List<prosto> pso = prostoService.Getall();
		return new SimpleResult(pso);
	}
	
	@RequestMapping("/delBypid/{pid}")
	@ResponseBody
	public SimpleResult DEL(@PathVariable("pid") int id){
		int count = prostoService.delbyPid(id);
		return new SimpleResult(count>0?true:false);
	}
	
	@RequestMapping("/cdgbypid/{pid}")
	public String Getbypid(@PathVariable("pid") int pid,Model model){
		prosto bs = prostoService.getByid(pid);
		model.addAttribute("bs", bs);
		return "product/updByStock";
	}
	@RequestMapping("/updbypid")
	public String UpdBypid(prosto ps){
		int pros = prostoService.updBypid(ps);
		if(pros!=0){
			return "redirect:go";
		}else{
			return "redirect:go";
		}
	}
	@RequestMapping("/GetByid/{pid}")
	public @ResponseBody SimpleResult GetByid(@PathVariable("pid") int aid) {
		List<prosto> getByid = prostoService.getBypid(aid);
		return new SimpleResult(getByid);
	}
	@RequestMapping("/GetByname/{pname}")
	public @ResponseBody SimpleResult GetByname(@PathVariable("pname") String pname) {
		List<prosto> getByname= prostoService.getBypname(pname);
		return new SimpleResult(getByname);
	}

	@RequestMapping("/go")
	public String prostoList() {
		return "product/stock/stock_list";
	}
}
